﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using LPV_POS.In;
using LPV_POS;
using LPV_POS.Module;
using LPV_POS.Baocao;
using LPV_POS.Baocao.Ellic;


    class Mod_baocaodoanhthu_tatca_in
    {
        //Boolean bInComPort = false;
        DataTable tb;
        string tencongty = "";
        string dienthoai = "";
        string diachi = "";

        int i1 = 42;
        
        
        string Print_Align_Left = ((char)(27)).ToString() + ((char)(97)).ToString() + '\0';

        #region "   f_splitString2Column"
        string f_splitString2Column(string a, string b, int i1)
        {//i1: 32; i2:7; i3: 17
            string str = "";
            str = a;
            str += new cpublic().Spacestring(i1 - a.Length - b.Length);
            str += b;
            return str;
        }
        #endregion
        //------------In doanh thu----------26/06/2012---------------------------
        public void f_baocaodoanhthu_tatca_in(string lbel_tongcongchuatanggiam, string lbel_giamgia_1, string lbel_vat_1, string lbel_thuedichvu_1, string lbel_tientip_1, string lbel_tongcongdagiamthue, string lbel_datanggiam, string phuthu, string thu, string chi, string congno, string khuyenmai, string datcoc, string trudatcoc, string tienmat, string the) //bc httt, editor: 2012.07.25
        {
                Mod_header_report header_report = new Mod_header_report();
                tb = header_report.f_selectheaderreport();
                if (tb.Rows.Count > 0)
                {
                    tencongty = tb.Rows[0]["HEADER"] + "";
                    dienthoai = tb.Rows[0]["PHONE"] + "";
                    diachi = tb.Rows[0]["ADDRESS"] + "";
                }

                thuvien tv = new thuvien();
                DataTable tbTMP = tv.SP_SelectDataTable("sp_DM_MAYIN_BIENNHAN", null, null);
                DataView dv = tbTMP.DefaultView;
                dv.Sort = "COMNAME";
                int vitri = dv.Find(new object[] { "USB" });
                int vitri_bixolon = dv.Find(new object[] { "BIXOLON" });
                int vitri_bixolon_100 = dv.Find(new object[] { "BIXOLON100" });
                if (vitri > -1 || vitri_bixolon > -1 || vitri_bixolon_100 > -1)
                //if (!bInComPort)
                {
                    #region "in bill tieng viet"
                    bc_BaoCaoDoanhThu_TongQuat rpt = new bc_BaoCaoDoanhThu_TongQuat();
                    rpt.DataDefinition.FormulaFields["tencongty"].Text = "'" + tencongty.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["dienthoai"].Text = "'" + dienthoai.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["diachi"].Text = "'" + diachi.Trim() + "'";
                    rpt.DataDefinition.FormulaFields["ngayin"].Text = "'" + "In báo cáo ngày " + DateTime.Today.ToString("dd/MM/yyyy") + "'";
                    //
                    rpt.DataDefinition.FormulaFields["tong_cong_chua_giam_gia"].Text = "'" + "1. Tổng cộng chưa giảm giá:  " + lbel_tongcongchuatanggiam + "'";
                    rpt.DataDefinition.FormulaFields["giam_gia"].Text = "'" + " Giảm giá:  " + lbel_giamgia_1 + "'";
                    rpt.DataDefinition.FormulaFields["tong_cong_da_giam_gia"].Text = "'" + "2. Tổng cộng đã giảm giá:  " + lbel_tongcongdagiamthue + "'";
                    rpt.DataDefinition.FormulaFields["thue_vat"].Text = "'" + " Thuế VAT:  " + lbel_vat_1 + "'";
                    rpt.DataDefinition.FormulaFields["phi_dich_vu"].Text = "'" + " Phí dịch vụ:  " + lbel_thuedichvu_1 + "'";
                    rpt.DataDefinition.FormulaFields["tien_tip"].Text = "'" + " Tiền tip:  " + lbel_tientip_1 + "'";
                    rpt.DataDefinition.FormulaFields["phu_thu"].Text = "'" + " Phụ thu:  " + phuthu + "'";
                    rpt.DataDefinition.FormulaFields["khuyen_mai"].Text = "'" + " Khuyến mãi:  " + khuyenmai + "'";
                    rpt.DataDefinition.FormulaFields["thu"].Text = "'" + " Thu:  " + thu + "'";
                    rpt.DataDefinition.FormulaFields["chi"].Text = "'" + " Chi:  " + chi + "'";
                    rpt.DataDefinition.FormulaFields["dat_coc"].Text = "'" + " Đặt cọc :  " + datcoc + "'";//---------------26/06/2012--thêm đặt cọc--vào báo cáo doanh thu
                    rpt.DataDefinition.FormulaFields["tru_dat_coc"].Text = "'" + " Trừ đặt cọc :  " + trudatcoc + "'";//---------------26/06/2012--thêm trừ đặt cọc--vào báo cáo doanh thu
                    rpt.DataDefinition.FormulaFields["khach_hang_no"].Text = "'" + " Khách hàng nợ:  " + congno + "'";
                    rpt.DataDefinition.FormulaFields["tong_cong_da_tang_giam"].Text = "'" + "3. Tổng cộng đã tăng giảm:  " + lbel_datanggiam + "'";

                    rpt.DataDefinition.FormulaFields["tong_tienmat"].Text = "'" + " Tiền mặt:  " + tienmat + "'"; //--bc theo httt, editor: PL, date: 2012.07.25
                    rpt.DataDefinition.FormulaFields["tong_the"].Text = "'" + " Thẻ :  " + the + "'";            //--bc theo httt, editor: PL, date: 2012.07.25

                    #region "   PrinterDefault"
                    System.Drawing.Printing.PrinterSettings cls = new System.Drawing.Printing.PrinterSettings();
                    string sPrinterDefault = cls.PrinterName;
                    if (sPrinterDefault != "")
                        rpt.PrintOptions.PrinterName = sPrinterDefault;


                    try
                    {
                        if (new cpublic().Registry_Get("chkCrystalReport_Display") + "" == "True")
                        {
                            mh_View frm = new mh_View(rpt);
                            frm.Show();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    #endregion
                    
                    rpt.PrintToPrinter(1, true, 1, 100);
                    rpt.Dispose();//-----Xóa file tmp rpt---07/07/2012
                    #endregion
                    
                }
                else
                {
                    // Khởi tao class in bill 2:
                    PrintCOMs oPrintCOMs = new PrintCOMs(PrintCOMs.Print_Type.Print_BILL);
                    SerialPort_LPV[] aSerialPort_LPV = oPrintCOMs.Print_Start();
                    foreach (SerialPort_LPV oSerialPort_LPV in aSerialPort_LPV)
                    {
                        if (oSerialPort_LPV != null)
                        {
                            #region "   //=======================================HEADER==============================================================================="
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Double_Height, "BAO CAO DOANH THU TONG QUAT", "", "", "");
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Variable.str_tungay, "", "", "");

                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                            if (tencongty != "")
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, tencongty, "", "", "");
                            if (dienthoai != "")
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, dienthoai, "", "", "");
                            if (diachi != "")
                                oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, diachi, "", "", "");

                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                            #endregion

                            #region "   //==================================================DETAIL===================================================================="
                            //lay dataset cua doanh thu theo nhom chu
                            if (lbel_tongcongchuatanggiam != "0")
                            {

                                oSerialPort_LPV.WriteLine(f_splitString2Column("1. Tong cong chua giam gia", lbel_tongcongchuatanggiam, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Giam gia", lbel_giamgia_1, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column("2. Tong cong da giam gia", lbel_tongcongdagiamthue, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Thue VAT", lbel_vat_1, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Phi dich vu", lbel_thuedichvu_1, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Tien tip", lbel_tientip_1, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Phu thu", phuthu, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Khuyen mai", khuyenmai, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Thu", thu, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Chi", chi, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Khach hang no", congno, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column("3. Tong cong da tang giam", lbel_datanggiam, i1));
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" Tien mat", tienmat, i1)); // bc httt, editor: PL, date: 2012.07.25
                                oSerialPort_LPV.WriteLine(f_splitString2Column(" The", the, i1)); // bc httt, editor: PL, date: 2012.07.25
                            }
                            else
                            {
                                Mod_messagebox mess = new Mod_messagebox();
                                mess.messagebox_pos("Thông báo", "Chưa có doanh thu", loaithongbao.canhbao.GetHashCode());
                                return;
                            }
                            #endregion

                            #region "   //=======================================FOOTER==============================================================================="
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, '=', PrintCOMs.Fills.Fills_Full);
                            oPrintCOMs.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Normal, "Ngày in bill " + DateTime.Today.ToString("dd/MM/yyyy"), "", "", "");
                            oPrintCOMs.Print_Line(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, ' ', PrintCOMs.Fills.Fills_Full);

                            oPrintCOMs.Print_Bottom(oSerialPort_LPV);
                            oPrintCOMs.Print_Close();
                            #endregion
                        }
                    }
                }
        }
        void a()
        {
            
        }

      

    }

